
'use strict'

// 格式化数字，使其成为两位数的字符串
function formatDateTimePart (part) {
  return part < 10 ? `0${part}` : `${part}`
}

// 获取当前时间戳，考虑使用更明确的函数名
export function getCurrentTimestamp () {
  return (new Date()).valueOf()
}

// 提供一个模块级别的当前日期时间实例
const currentDate = new Date()

// 获取格式化的当前日期时间对象
export function DateTime () {
  const year = currentDate.getFullYear()
  let month = currentDate.getMonth() + 1
  let date = currentDate.getDate()

  const hour = currentDate.getHours()
  let minute = currentDate.getMinutes()
  let second = currentDate.getSeconds()

  month = formatDateTimePart(month)
  date = formatDateTimePart(date)
  minute = formatDateTimePart(minute)
  second = formatDateTimePart(second)

  return { year, month, date, hour, minute, second }
}

// 获取当前日期
export function GetDate () {
  const data = DateTime()
  return `${data.year}-${data.month}-${data.date}`
}

// 获取当前时间
export function GetTime () {
  const data = DateTime()
  return `${data.hour}:${data.minute}:${data.second}`
}

// 获取当前星期
export function GetWeek () {
  const data = DateTime()
  const weekday = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  return weekday[data.day]
}
// 获取当前时间戳
export function GetTimestamp () {
  return (new Date()).valueOf()
}

// 获取年于日时分秒
export function GetYearMonthDayHourMinuteSecond () {
  const data = DateTime()
  return `${data.year}${data.month}${data.date}${data.hour}${data.minute}${data.second}`
}
